package com.neutech.controller;

import com.google.gson.Gson;
import com.neutech.entity.User;
import com.neutech.service.DeliveryAddressService;
import com.neutech.service.impl.DeliveryAddressServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/order/deliveryAddressList")
public class DeliveryAddressListServlet extends HttpServlet {

    private DeliveryAddressService deliveryAddressService = new DeliveryAddressServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        User user = (User) req.getSession().getAttribute("user");
        out.print(new Gson().toJson(deliveryAddressService.listByUserId(user.getId())));
    }
}
